package com.cs.study.homework._0227;

import java.util.Objects;

public class Demo4 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Teacher teacher = new Teacher(20,"ww");
        Teacher clone = (Teacher) teacher.clone();
        System.out.println(teacher);
        System.out.println(clone);
        System.out.println(teacher.equals(clone));
        teacher.age = 30;
        System.out.println(clone.age);
    }
}

class Teacher implements Cloneable {
    int age;
    String name;
    Student stu;

    public Teacher(int age, String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Teacher teacher = (Teacher) o;
        return age == teacher.age && Objects.equals(name, teacher.name) && Objects.equals(stu, teacher.stu);
    }

    @Override
    public int hashCode() {
        return Objects.hash(age, name, stu);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", stu=" + stu +
                '}';
    }
}

class Student {
    int age;
    String name;
    Star s;

    public Student(int age, String name) {
        this.age = age;
        this.name = name;
    }
}

class Star {
    int age;
    String name;

    public Star(int age, String name) {
        this.age = age;
        this.name = name;
    }

    public Star() {
    }
}
